package yf.mall.controller;

import java.util.List;

import yf.mall.vo.CourseSumVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;

import java.util.Map;

import com.yf.consts.DaoConst;
import yf.mall.entity.CourseEntity;
import yf.mall.service.CourseService;
import com.yf.response.R;


/**
 * 讲堂Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Mon Oct 21 08:39:57 CST 2019
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 列表讲堂
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params), DaoConst.getLIMIT(params));
        List<CourseEntity> courseList = courseService.queryList(params);
        return R.ok(new PageInfo(courseList));
    }

    /**
     * 查看讲堂
     */
    @SysLog("查看讲堂")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:info")
    public R info(@PathVariable("id") Long id) {
        CourseEntity course = courseService.get(id);

        return R.ok(course);
    }

    /**
     * 保存讲堂
     */
    @SysLog("保存讲堂")
    @RequestMapping("/save")
    @RequiresPermissions("course:save")
    public R save(CourseEntity course) {
        courseService.save(course);

        return R.ok(course);
    }

    /**
     * 修改讲堂
     */
    @SysLog("修改讲堂")
    @RequestMapping("/update")
    @RequiresPermissions("course:update")
    public R update(CourseEntity course) {
        courseService.update(course);

        return R.ok(course);
    }

    /**
     * 删除讲堂
     */
    @SysLog("删除讲堂")
    @RequestMapping("/delete")
    @RequiresPermissions("course:delete")
    public R delete(Long[] ids) {
        courseService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有讲堂
     */
    @SysLog("所有讲堂")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<CourseEntity> courseList = courseService.queryList(params);

        return R.ok(courseList);
    }

    /**
     @ModelAttribute public SearchParam<CourseEntity> searchParam(SearchParam<CourseEntity> params, CourseEntity course) {
     if (course != null) {
     params.setEntity(course);
     }

     return params;
     }
     **/
    /***********自定义开始***********/


    /**
     * 所有讲堂
     */
    @SysLog("统计报名")
    @RequestMapping("/sum")
    public R sum(Long courseId) {
        List<CourseSumVo> courseList = courseService.sumSign(courseId);
        return R.ok(courseList);
    }

}
